package healththink

class FacilityGroup{
    String groupName
    String summary

    static hasMany = [facilities: FacilityGroupLink,
		facilityGroupUsers: FacilityGroupUserLink]

    static constraints = {
		groupName(size:1..64, blank:false)
		summary(size:1..2048, nullable:true)
    }
    
    String toString(){
        groupName
    }
    
    /* Facility Group User Link */
    List facilityGroupUsers()
    {
        return facilityGroupUsers.collect{it.user}
    }
    
    List addToFacilityGroups(User facilityGroupUser)
    {
        FacilityGroupUserLink.link(facilityGroupUser, this)
        return facilityGroupUsers()
    }
    
    List removeFromFacilityGroups(User facilityGroupUser)
    {
        FacilityGroupUserLink.unlink(facilityGroupUser, this)
        return facilityGroupUsers()
    }
    
    List facilities(){
        return facilities.collect{it.facility}
    }
    
    List addToFacilities(Facility facility){
        FacilityGroupLink.link(facility, this)
        return facilities()
    }
    
    List removeFromFacilities(Facility facility){
        FacilityGroupLink.unlink(facility, this)
        return facilities()
    }
}